#include <stdio.h>

void read_vector(int[], int);
// void move_one_element(int[], int);
void swap(int[], int, int);

int main()
{
    int vector_size;
    printf("Input the vector length: ");
    scanf(" %d", &vector_size);

    int move_length;
    printf("Enter the value of move_length: ");
    scanf(" %d", &move_length);
    move_length = move_length % vector_size;

    int input_vector[vector_size];
    printf("Input the vector: ");
    read_vector(input_vector, vector_size);

    // 第一种实现
    // for (int i = 0; i < move_length; i++)
    //     move_one_element(input_vector, vector_size);
    
    // 第二种实现
    swap(input_vector, 0, vector_size - 1);
    swap(input_vector, 0, move_length - 1);
    swap(input_vector, move_length, vector_size - 1);

    for (int i = 0; i < vector_size; i++)
        printf("%d ", input_vector[i]);
    printf("\n");

    return 0;
}

void read_vector(int original_vector[], int vector_size)
{
    for (int i = 0; i < vector_size; i++)
        scanf(" %d", &original_vector[i]);
}

// void move_one_element(int original_vector[], int vector_size)
// {
//     int temp_value = original_vector[vector_size - 1];
//     for (int i = vector_size - 1; i >= 0; i--) 
//         original_vector[i] = original_vector[i - 1];
//     original_vector[0] = temp_value;
// }

void swap(int original_vector[], int swap_start, int swap_end)
{
    int temp_value = 0;
    for (int i = swap_start; i < swap_end; i++) {
        temp_value = original_vector[i];
        original_vector[i] = original_vector[swap_end];
        original_vector[swap_end--] = temp_value;
    }
}
